#include <iostream>

#include <memory>
#include "UdpServer.hpp"
#include "MessageRoute.hpp"

//using func_t = std::function<void(int sockfd,std::string message,const InetAddr& who)>;

void Usage(const std::string& tip)
{
    std::cout << "Please Use:\n\t" << tip << " local_port\n" << std::endl;
}

int main(int argc,char* argv[])
{
    if(argc !=2)
    {
        Usage(argv[0]);
        exit(USAGE_ERROR);
    }

    EnableScreen();

    MessageRoute msgrt;

    uint16_t port = std::stoi(argv[1]);
   

    std::unique_ptr<UdpServer> usvr = std::make_unique<UdpServer>(port,\
    std::bind(&MessageRoute::Route,&msgrt,std::placeholders::_1,std::placeholders::_2,std::placeholders::_3));
    
    usvr->InitServer();
    usvr->Start();

}



// #include <iostream>

// #include <memory>
// #include "UdpServer.hpp"

// void Usage(const std::string& tip)
// {
//     std::cout << "Please Use:\n\t" << tip << " local_ip local_port\n" << std::endl;
// }

// int main(int argc,char* argv[])
// {
//     if(argc !=3)
//     {
//         Usage(argv[0]);
//         exit(USAGE_ERROR);
//     }

//     EnableScreen();

//     std::string ip = argv[1];
//     uint16_t port = std::stoi(argv[2]);

//     std::unique_ptr<UdpServer> usvr = std::make_unique<UdpServer>(ip,port);
//     usvr->InitServer();
//     usvr->Start();

// }